package homepage

import (
	"github.com/gin-gonic/gin"
	"go-papers/models"
	"go-papers/tools"

	"go-papers/tools/app"
)

func GetBannerList(c *gin.Context) {
	result := []string{"1", "2", "3"}
	count := len(result)
	pageIndex := 1
	pageSize := 10
	app.PageOK(c, result, count, pageIndex, pageSize, "")
}

func GetSpecial(c *gin.Context) {
	var data models.SpecialContent
	var err error
	var pageSize = 10
	var pageIndex = 1

	if size := c.Request.FormValue("pageSize"); size != "" {
		pageSize = tools.StrToInt(err, size)
	}
	if index := c.Request.FormValue("pageIndex"); index != "" {
		pageIndex = tools.StrToInt(err, index)
	}

	data.SpecialStatus = "5"
	data.SpecialCode = c.Request.FormValue("specialCode")
	data.SpecialName = c.Request.FormValue("specialName")

	result, count, err := data.GetSearchPage(pageSize, pageIndex)
	if err != nil {
		app.ApiResp(c, -1, "数据查询失败："+err.Error(), nil)
		return
	}
	app.PageOK(c, result, count, pageIndex, pageSize, "")

}

// GetSpecialInfo
func GetSpecialInfo(c *gin.Context) {
	var data models.SpecialContent
	var err error

	data.SpecialId, _ = tools.StringToInt(c.Param("id"))
	data.SpecialStatus = "5"

	result, err := data.Get()
	if err != nil {
		app.ApiResp(c, -1, "数据查询失败："+err.Error(), nil)
		return
	}
	app.OK(c, result, "")

}
